<template>
    <div>
            <table>
                  <tr>
                       <td>头像</td>
                       <td>
                          <input type="file" @change="sc">
                          <img :src="'https://localhost:7059/' + data.Ytp" style="width: 60px; height: 60px;" >
                       </td>
                  </tr>
                  <tr>
                       <td>员工姓名</td>
                       <td>
                           <input type="text" v-model="data.Yname">
                       </td>
                  </tr>
                    <tr>
                       <td>联系方式</td>
                       <td>
                           <input type="text" v-model="data.Yphone">
                       </td>
                  </tr>
                    <tr>
                       <td>角色</td>
                       <td>
                           <select v-model="data.Ylxid">
                                 <option v-for="d in xl" :value="d.Jid">{{d.Jname}}</option>
                           </select>
                       </td>
                  </tr>
                    <tr>
                       <td>登录密码</td>
                       <td>
                         <input type="text" v-model="data.Ymm">
                       </td>
                  </tr>
                    <tr>
                       <td>状态</td>
                       <td>
                           <input type="radio" value="0" name="aaa" v-model="data.Yzt">启用
                           <input type="radio" value="1" name="aaa" v-model="data.Yzt">禁用
                       </td>
                  </tr>
                    <tr>
                       <td>备注</td>
                       <td>
                        <input type="text" v-model="data.Ybz">
                       </td>
                  </tr>
                    <tr>
                       <td></td>
                       <td>
                            <input type="button" value="添加" @click="add">
                       </td>
                  </tr>
            </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter} from 'vue-router'

const router = useRouter()

const sc=(Yid:any)=>{
    var f = Yid.target.files[0]
    var fd = new FormData()
    fd.append("file",f)
    axios.post("https://localhost:7059/api/YK/SC",fd).then(res=>{
        data.value.Ytp = res.data
    })
}

const data = ref({
  "Yid": 0,
  "Ytp": "string",
  "Yname": "",
  "Ybh": "",
  "Yphone": "",
  "Ylxid": 0,
  "Ymm": "",
  "Yzt": 0,
  "Ybz": "",
  "IsDelete": true
})

const add=()=>{

    if(data.value.Yname == ""){
        alert("姓名不能为空!");
        return ;
    }
      if(data.value.Yphone == ""){
        alert("联系方式不能为空!");
        return ;
    }
      if(data.value.Ymm == ""){
        alert("登录密码不能为空!");
        return ;
    }

    axios.post("https://localhost:7059/api/YK/Add",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功!");
            router.push("/Show/");
        }
        else{
            alert("添加失败");
        }
    })
}

onMounted(()=>{
  Bang()
})

const xl = ref([{
     "Jid": 1,
    "Jname": "管理员"
}])

const Bang=()=>{
    axios.get("https://localhost:7059/api/YK/Bang").then(res=>{
        xl.value = res.data
    })
}


</script>

<style scoped>

</style>